<?php
/**
 * Hy - 系统信息模块
 *
 * Site站点参数，用于提供后台的系统运行参数配置，如系统名称，系统网站，公司名称，备案号等信息
 * Sys系统参数，用于提供后台其他系统运行必要参数的配置入口，如电子邮件参数配置
 *
 * Copyright (c) 2013 YinHailin All rights reserved.
 * @Author: YinHailin
 * @Authorize: Boren Network
 * @Created by YinHailin at 2013-11-20
 */

defined('LY_VERSION') or exit();

class SystemMod extends PublicMod {

  /* 站点参数 */
  public function Site() {
    parent::GetGlobal();  //调用公共方法
    parent::CheckLogin(false);  //检查登录
    parent::CheckPurview('site');  //权限判断

    $objSite = M(self::$dataSite);

    if ($_POST) {
      $POST = deep_htmlspecialchars($_POST);
      parent::CheckField('site_name', $POST['site_name'], 'require', '站点名称不能为空');
      parent::CheckField('site_url', $POST['site_url'], 'require', '站点URL不能为空');
      parent::CheckField('company', $POST['company'], 'require', '公司名称不能为空');
      if ($POST['email'] != '') parent::checkField('email', $POST['email'], 'email', 'Email格式错误');
      $data['site_name'] = $POST['site_name'];
      $data['site_url'] = $POST['site_url'];
      $data['company'] = $POST['company'];
      $data['address'] = $POST['address'];
      $data['zipcode'] = $POST['zipcode'];
      $data['telephone'] = $POST['telephone'];
      $data['cellphone'] = $POST['cellphone'];
      $data['email'] = $POST['email'];
      $data['icp'] = $POST['icp'];
      $data['third_code'] = $POST['third_code'];
      $objSite->Where('`id`=1')->Save($data);
      $this->Success('保存成功！', '/admin.php?m=system&a=site');
    } else {
      $data = $objSite->Where('`id`=1')->Find();
      $data = deep_htmlspecialchars_decode($data);
      $this->Assign('data', $data);

      $this->Display();
    }
  }

  /* 系统参数 */
  public function Sys() {
    parent::GetGlobal();  //调用公共方法
    parent::CheckLogin(false);  //检查登录
    parent::CheckPurview('sys');  //权限判断

    $objSystem = M(self::$dataSystem);

    if ($_POST) {
      $POST = deep_htmlspecialchars($_POST);
      //插件程序处理调用
      $data = rabbet('sys_func', 'sys_deal', $POST);
      if ($data != null) {
        $objSystem->Where('`id`=1')->Save($data);
      }
      $this->Success('保存成功！', '/admin.php?m=system&a=sys');
    } else {
      $data = $objSystem->Where('`id`=1')->Find();
      $data = deep_htmlspecialchars_decode($data);
      $this->Assign('data', $data);

      $this->Display();
    }
  }
}